package com.lpf.nio;

import java.nio.IntBuffer;
import java.security.SecureRandom;

/**
 * 功能描述：展示IntBuffer的使用
 *
 * @author lpf
 * @date 2019/11/24 21:27
 * @version: 1.0
 **/
public class NioTest01 {

    public static void main(String arg[]) {

        // 创建大小为10的缓冲区
        IntBuffer buffer = IntBuffer.allocate(10);

        for (int i = 0; i < buffer.capacity(); i++) {
            // SecureRandom继承自Random类。SecureRandom生成的数更随机
            int randomNumber = new SecureRandom().nextInt(20);
            buffer.put(randomNumber);
        }

        buffer.flip();

        while (buffer.hasRemaining()) {
            System.out.println(buffer.get());
        }
    }
}
